package com.seanchenxi.gwt.wordpress.xmlrpc.service.model.handler;

import java.util.ArrayList;

import com.seanchenxi.gwt.wordpress.domain.model.Comment;
import com.seanchenxi.gwt.wordpress.xmlrpc.service.model.impl.ModelFactory;
import com.seanchenxi.gwt.xmlrpc.client.impl.BaseResponseHandler;

public class CommentsResponseHandler extends BaseResponseHandler<ArrayList<Comment>>{
	@Override
	public ArrayList<Comment> handleResponse(String response) {
		Object object = super.handleResponse(response);
		
		if(ModelFactory.isNotList(object)) return null;
		
		ArrayList<Comment> comments = new ArrayList<Comment>();
		for(Object obj : (ArrayList<?>)object){
			Comment comment = ModelFactory.ToComment(obj);
			if(comment!=null && !comments.contains(comment)){ 
				comments.add(comment);
			}
		}
			
		return comments;
	}
}
